package com.ldl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.ldl.dao.UserDao;
import com.ldl.entity.User;
import com.ldl.util.DBHelper;

/**
 * @author Administrator
 * Author : L.D.L
 * E-mail : 1419485293@qq.com
 * Date : 2020年8月4日下午7:43:31
 */
public class UserDaoImpl implements UserDao{

	@Override
	public List<User> login(String userName) throws SQLException {
		String sql = "select * from user where user_name = '"+userName+"'";
		List<User> list = new ArrayList<User>();
		try(
				Connection conn = DBHelper.getConn();
				PreparedStatement ps = conn.prepareStatement(sql);
				ResultSet res = ps.executeQuery();
			){
			while(res.next()){
				User u = new User();
				u.setUserId(res.getInt("user_id"));
				u.setUserName(res.getString("user_name"));
				u.setUserPwd(res.getString("user_password"));
				u.setUserPhone(res.getString("user_phone"));
				list.add(u);
			}
			return list;
		}
	}

}
